package com.SHA1604.tiger.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.SHA1604.tiger.R;
import com.SHA1604.tiger.adapter.RecomandVPAdapter;
import com.SHA1604.tiger.app.IApp;
import com.SHA1604.tiger.bean.RecomandTitleBean;
import com.gc.flashview.FlashView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by cay on 2016/7/28.
 */
public class RecomandTitleView extends LinearLayout {


    private Context mContext;
    private ArrayList<String> mTopimag;
    private List<RecomandTitleBean.DataBean.ZoneBean> mZoneData;
    private List<ImageView> mSelected;

    private FlashView mFlv;
    private TextView mTv_one,mTv_two,mTv_three,mTv_four,mTv_five,mTv_six;
    private TextView mTv_th_one,mTv_th_two,mTv_th_three,mTv_th_four,mTv_th_five,mTv_th_six;
    private ImageView mIv_one,mIv_two,mIv_three,mIv_th_one,mIv_th_two,mIv_th_three;
    private ViewPager mVp_recomand;
    private TextView mTv_four_select;


    public RecomandTitleView(Context context) {
        this(context, null);
    }

    public RecomandTitleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RecomandTitleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }


    private void initView() {
        LayoutInflater.from(mContext).inflate(R.layout.recommand_title, this);
        mTopimag = new ArrayList<>();
        mZoneData = new ArrayList<>();
        mSelected = new ArrayList<>();
        mFlv = (FlashView) findViewById(R.id.fv_recomand_title);
        mTv_one = (TextView) findViewById(R.id.tv_one);
        mTv_two = (TextView) findViewById(R.id.tv_two);
        mTv_three = (TextView) findViewById(R.id.tv_three);
        mTv_four = (TextView) findViewById(R.id.tv_four);
        mTv_five = (TextView) findViewById(R.id.tv_five);
        mTv_six = (TextView) findViewById(R.id.tv_six);
        mIv_one = (ImageView) findViewById(R.id.iv_one);
        mIv_two = (ImageView) findViewById(R.id.iv_two);
        mIv_three = (ImageView) findViewById(R.id.iv_three);

        mTv_th_one = (TextView) findViewById(R.id.tv_th_one);
        mTv_th_two = (TextView) findViewById(R.id.tv_th_two);
        mTv_th_three = (TextView) findViewById(R.id.tv_th_three);
        mTv_th_four = (TextView) findViewById(R.id.tv_th_four);
        mTv_th_five = (TextView) findViewById(R.id.tv_th_five);
        mTv_th_six = (TextView) findViewById(R.id.tv_th_six);
        mIv_th_one = (ImageView) findViewById(R.id.iv_three_one);
        mIv_th_two = (ImageView) findViewById(R.id.iv_three_two);
        mIv_th_three = (ImageView) findViewById(R.id.iv_three_three);

        mVp_recomand = (ViewPager) findViewById(R.id.vp_recommand);
       // mTv_four_select = (TextView) findViewById(R.id.tv_four_selected);
    }

    public void setData(RecomandTitleBean data){
        if (data !=null){
            //頭部flasview数据
            for (int i = 0; i <data.getData().getTopic().size() ; i++) {
                String img_url = data.getData().getTopic().get(i).getImg_url();
                mTopimag.add(img_url);
            }
            mFlv.setImageUris(mTopimag);

            //中间布局数据
            List<RecomandTitleBean.DataBean.ZoneBean> zone = data.getData().getZone();
            mTv_one.setText(zone.get(0).getTitle());
            mTv_two.setText(zone.get(0).getSub_title());
            Picasso.with(mContext).load(zone.get(0).getImg_url()).into(mIv_one);

            mTv_three.setText(zone.get(1).getTitle());
            mTv_four.setText(zone.get(1).getSub_title());
            Picasso.with(mContext).load(zone.get(1).getImg_url()).into(mIv_two);

            mTv_five.setText(zone.get(2).getTitle());
            mTv_six.setText(zone.get(2).getSub_title());
            Picasso.with(mContext).load(zone.get(2).getImg_url()).into(mIv_three);

            //底部数据
            List<RecomandTitleBean.DataBean.ChannelBean> channel = data.getData().getChannel();
            mTv_th_one.setText(channel.get(0).getTitle());
            mTv_th_two.setText(channel.get(0).getSub_title());
            Picasso.with(mContext).load(channel.get(0).getImg_url()).into(mIv_th_one);

            mTv_th_three.setText(channel.get(1).getTitle());
            mTv_th_four.setText(channel.get(1).getSub_title());
            Picasso.with(mContext).load(channel.get(1).getImg_url()).into(mIv_th_two);

            mTv_th_five.setText(channel.get(2).getTitle());
            mTv_th_six.setText(channel.get(2).getSub_title());
            Picasso.with(mContext).load(channel.get(2).getImg_url()).into(mIv_th_three);

            //精选专题数据
            List<RecomandTitleBean.DataBean.BannerBean> banner = data.getData().getBanner();
            for (int i = 0; i < banner.size(); i++) {
                ImageView imageView = new ImageView(mContext);
//                ViewPager.LayoutParams params =
//                        new ViewPager.LayoutParams(, ViewPager.LayoutParams.MATCH_PARENT);
                Picasso.with(mContext).load(banner.get(i).getImg_url()).into(imageView);
                mSelected.add(imageView);
            }
            mVp_recomand.setAdapter(new RecomandVPAdapter(mContext,mSelected));


        }

    }

}
